<!DOCTYPE html>
<html lang="en"  xmlns:th="http://www.thymeleaf.org">
    <head>
        <meta charset="UTF-8">
        <title>事件管理</title>
        <link rel="stylesheet" href="../../component/pear/css/pear.css"/>
    </head>
    <body>
        <form class="layui-form" action="">
            <div class="mainBox">
                <div class="main-container">
                    <div class="main-container">
                        <input type="hidden" name="id" value="${eventInfo.id!}">
                        <input type="hidden" name="createTime" value="${eventInfo.createtime!}">
                        <div class="layui-form-item">
                            <label class="layui-form-label">事件名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="eventName" lay-verify="required" value="${eventInfo.eventName!}" autocomplete="off" placeholder="请输入角色名称" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">事件分类</label>
                            <div class="layui-input-block">
                                <select name="eventType" lay-verify="required">
                                    <option value="" selected>请选择</option>
                                    @for(item in eventType!){
                                    <option value="${item.id}" ${item.id==(eventInfo.eventType!)?'selected':''}>${item.typeName!}</option>
                                    @}
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">事件图标</label>
                            <div class="layui-input-block">
                                <input type="text" name="icon" id="iconPicker" value="${eventInfo.icon!'layui-icon-set'}" lay-filter="iconPicker" class="hide" autocomplete="off">
                            </div>
                        </div>
                        <div class="layui-form-item" style="display: none;">
                            <label class="layui-form-label">算法编号</label>
                            <div class="layui-input-block">
                                <input type="number"  name="algorithmId" lay-verify="number" required autocomplete="off" value="${eventInfo.algorithmId!1}" placeholder="请输入算法编号" class="layui-input" autocomplete="off">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">算法名</label>
                            <div class="layui-input-block">
                                <input type="text"  name="algorithm" lay-verify="required" required autocomplete="off" value="${eventInfo.algorithm!}" placeholder="请输入算法名" class="layui-input" autocomplete="off">
                            </div>
                        </div>
                        <!--<div class="layui-form-item">
                            <label class="layui-form-label">违章消息</label>
                            <div class="layui-input-block">
                                <input type="text"  name="algorithmKey" lay-verify="required" required autocomplete="off" value="${eventInfo.algorithmKey!}" placeholder="请输入算违章消息" class="layui-input" autocomplete="off">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">默认启用</label>
                            <div class="layui-input-block">
                                <input type="checkbox" name="status" lay-skin="switch" lay-text="是|否" ${eventInfo.status!1==1?'checked':''}>
                            </div>
                        </div>-->
                        <div class="layui-form-item">
                            <label class="layui-form-label">备注</label>
                            <div class="layui-input-block">
                                <input type="text" name="remark" lay-verify="required" value="${eventInfo.remark!}" autocomplete="off" placeholder="请输入备注" class="layui-input" autocomplete="off">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">状态</label>
                            <div class="layui-input-block">
                                <input type="checkbox" name="enable" lay-skin="switch" lay-text="启用|禁用" ${eventInfo.enable!1==1?'checked':''}>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="bottom">
                <div class="button-container">
                    <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="event-save">
                        <i class="layui-icon layui-icon-ok"></i>
                        提交
                    </button>
                    <button type="reset" class="pear-btn pear-btn-sm">
                        <i class="layui-icon layui-icon-refresh"></i>
                        重置
                    </button>
                </div>
            </div>
        </form>
        <script src="../../component/layui/layui.js"></script>
        <script src="../../component/pear/pear.js"></script>
        <script>
            layui.use(['form','jquery','icon','dtree'],function(){
                let form = layui.form;
                let $ = layui.jquery;
                let icon = layui.icon;
                dtree = layui.dtree;

                let MODULE_PATH = "${ctxPath}/event/";

                icon.render({
                    elem: '#iconPicker'
                    ,style: 'color: #5FB878;'
                    ,placeholder: '请选择图标'
                    ,isSplit: true
                    ,page: true
                    ,search: false
                    ,click: function(obj){}
                    ,ready: function(){}});

                form.on('submit(event-save)', function(data){
                    data.field.enable = data.field.enable == "on"?1:0;
                    data.field.status = data.field.status == "on"?1:0;
                    $.ajax({
                        url: MODULE_PATH + 'data/save',
                        data:JSON.stringify(data.field),
                        dataType:'json',
                        contentType:'application/json',
                        type:'post',
                        success:function(result){
                            if(result.code == 0){
                                layer.msg(result.message,{icon:1,time:1000},function(){
                                    parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                                    parent.layui.table.reload("event-table");
                                });
                            }else{
                                layer.msg(result.message,{icon:2,time:1000});
                            }
                        }
                    })
                    return false;
                });
            })
        </script>
        <script>
        </script>
    </body>
</html>